<template>
    <view class="wanlpage-likes wanl-product col-2-20" :style="[pageData.style]">
        <wanl-product :dataList="dataList" :dataStyle="`col-${pageData.params.colthree}-${pageData.params.colmargin}`"
            :dataType="dataType" />
        <uni-load-more :status="status" :content-text="contentText" />
    </view>
</template>
<script>
export default {
    name: "WanlPageLikes",
    props: {
        lower: {
            type: Number,
            default: 0,
        },
        pageData: {
            type: Object,
            default: function () {
                return {
                    name: "猜你喜欢",
                    type: "score",
                    params: [],
                    style: [],
                    data: [],
                };
            },
        },
    },
    data() {
        return {
            dataList: [], //数据
            current_page: 1, //当前页码
            last_page: 1, //总页码
            status: "loading",
            contentText: {
                contentdown: "下拉加载更多",
                contentrefresh: "疯狂加载中...",
                contentnomore: "我是有底线的",
            },
            dataType: 'score',
        };
    },
    created() {
        this.loadData();
    },
    methods: {
        async loadData(type) {
            this.status = "loading";
            // 判断上拉还是下拉
            if (type === "lower") {
                if (this.current_page >= this.last_page) {
                    this.status = "noMore";
                    return false;
                } else {
                    this.current_page += 1;
                }
            }
            await uni.request({
                url: "/score/goods/GetGoodsList",
                data: {
                    page: this.current_page,
                    is_hot: 1
                },
                success: (res) => {
                    if (type === "lower") {
                        this.dataList = this.dataList.concat(res.data.data);
                    } else {
                        this.dataList = res.data.data;
                    }
                    this.current_page = res.data.current_page; //当前页码
                    this.last_page = res.data.last_page; //总页码
                    // 判断是否还有数据
                    if (res.data.current_page === res.data.last_page || res.data.total === 0) {
                        this.status = "noMore";
                    } else {
                        this.status = "more";
                    }
                },
            });
        },
    },
    watch: {
        lower(newVal, oldVal) {
            this.loadData("lower");
        },
    },
};
</script>
<style></style>
